<script setup lang="ts">
import { hideLoading, showLoading, usePullDownRefresh, stopPullDownRefresh } from '@tarojs/taro';

definePageConfig({
    navigationBarTitleText: '退款申请列表',
    enablePullDownRefresh: true
});
import { useNurseOrders } from '@/service';
import { storeToRefs } from 'pinia';
import { ref, computed } from 'vue';
import { useAuthStore } from '@/store';

import { useDayjs } from '@/hooks/common';

const { nurseUser } = storeToRefs(useAuthStore());

const { $dayjs } = useDayjs();

const { refundList } = useNurseOrders();

const list = ref();

usePullDownRefresh(() => {
    getData();
    stopPullDownRefresh();
});

getData();

const date = computed(() => (createTime: string) => {
    if (createTime) {
        const date = $dayjs(createTime).format('YYYY-MM-DD');
        return date;
    }
    return '';
});
async function getData() {
    showLoading({ title: '正在请求数据...' });

    const { error, success } = await refundList({ pageNo: 1, pageSize: 10, userId: nurseUser.value.id });

    if (!error && success?.records) list.value = [...success?.records];

    hideLoading();
}
</script>
<template>
    <basic-layout>
        <!-- <custom-navbar title="退款申请列表" showLeft /> -->
        <view class="w-375px flex-col-center">
            <nut-empty v-if="list?.length == 0" description="暂无退款"></nut-empty>
            <view class="w-360px">
                <nut-cell v-for="item in list" class="flex-col-center w-full">
                    <view class="w-full flex-center justify-between">
                        <view>{{ item.nurseType_dictText }}</view>
                        <view>{{ date(item.createTime) }}</view>
                    </view>
                    <view class="w-full flex-center justify-between">
                        <view>{{ item.goodsName }}</view>
                        <nut-tag v-if="item.status == '8'" type="warning">待处理</nut-tag>
                        <nut-tag v-if="item.status == '9'" type="primary">已驳回</nut-tag>
                        <nut-tag v-if="item.status == '5'" type="primary">退款中</nut-tag>
                        <nut-tag v-if="item.status == '6'" type="danger">退款异常</nut-tag>
                        <nut-tag v-if="item.status == '7'" type="success">退款成功</nut-tag>
                    </view>
                    <view class="w-full flex-center justify-start">
                        <view>{{ item.description }}</view>
                    </view>
                    <view class="w-full flex-center justify-start">
                        <view v-if="item.reply">客服回复：{{ item.reply }}</view>
                    </view>
                </nut-cell>
            </view>
        </view>
    </basic-layout>
</template>
